home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / NGL 2.0 Demo / NGL2.0.0(E)Demo / Hide Snow Demo / Hide Data Snow(PPC).c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-03  |  4.5 KB  |  222 lines

  1. /*============================================================
  2.  
  3.                     Hide data snow sample program
  4.                     
  5. ============================================================*/
  6.  
  7. #include        "N_Library.h"
  8.  
  9. void            Main_Process(void);
  10. void            Key_Process(void);
  11.  
  12. short            Data_Rsrc = 0;
  13. long                routine_step = 0;
  14. long                wait;
  15. short            S1_X[1024];
  16. short            S1_Y[1024];
  17. unsigned short        S1_D[1024];
  18. short            S1_MX[1024];
  19. short            S1_MY[1024];
  20. short            r = 0,rs=0;
  21. short            speed  = -3;
  22. Boolean            q = false;
  23. Boolean            kb=false;
  24. EventRecord        theEvent;
  25. short            Snd_List0[]     = {1000,1001,0};        
  26.  
  27. void main(void)
  28. {
  29.     WindowPtr    window;
  30.     short         i;
  31.  
  32.     ToolboxInit();
  33.     ColorCheck();
  34.     HideMenuBar();
  35.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  36.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  37.     N_Sp_Make(640,480);
  38.     N_Cel_Make2(640,480);
  39.  
  40.     N_Sp_Load("\pSnow Sprites");                                        
  41.     N_Pict_Load("\pSnow Graphics");                                    
  42.     N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                            
  43.     N_Sound_Load(&Snd_List0[0]);                                        
  44.  
  45. //    Button Set-up
  46.     N_Button_Set(0,0,1,10,404,512,0x80000000+100,0x80000000+101,1000,1001);    //Q Button
  47.     N_Button_Set(0,1,1,40,404,512,0x80000000+102,0x80000000+103,1000,1001);    //C Button
  48.     N_Button_Set(0,2,1,130,364,40,0x80000000+104,0x80000000+105,1000,1001);    //up Button
  49.     N_Button_Set(0,3,1,130,442,40,0x80000000+104,0x80000000+105,1000,1001);    //down Button
  50.     N_Button_Set(0,4,1,93,404,40,0x80000000+104,0x80000000+105,1000,1001);    //left Button
  51.     N_Button_Set(0,5,1,167,404,40,0x80000000+104,0x80000000+105,1000,1001);    //right Button
  52.  
  53.  
  54.     routine_step = 0;
  55.     for (i = 0;i!=1024;i++)
  56.     {
  57.         N_Cel_Kill(i);                                        
  58.         S1_X[i] = GetRandom(0,640*32)-640*16;                
  59.         S1_Y[i] = GetRandom(0,480*32)-480*16;
  60.         S1_D[i] = GetRandom(1,255);                            
  61.         S1_MX[i] = GetRandom(0,30)-15;
  62.         S1_MY[i] = GetRandom(0,30)-15;
  63.     }
  64.  
  65.     N_Pict_Effect (131,0,0,3,0,0);
  66.     for (i=0;i!=32;i++)
  67.     {
  68.         Delay(1,&wait);
  69.         N_Pict_Effect (131,0,0,3,1,0);
  70.         N_Pict_Effect (131,0,0,3,1,0);
  71.         N_Pict_Effect (131,0,0,3,1,0);
  72.         N_Pict_Effect (131,0,0,3,1,0);
  73.         N_Pict_Effect (131,0,0,3,1,0);
  74.         N_Pict_Effect (131,0,0,3,1,0);
  75.         N_Pict_Effect (131,0,0,3,1,0);
  76.         N_Pict_Effect (131,0,0,3,1,0);
  77.     }
  78.     N_Button_Put(0);
  79.  
  80.     do
  81.     {
  82.         Main_Process();
  83.     }
  84.     while (q==false);
  85.     N_Sound_Close();                                        
  86.     FlushEvents( everyEvent, 0 ); 
  87.     ShowMenuBar();
  88.     ColorRevert();
  89.  
  90. }
  91.  
  92. void Main_Process(void)
  93. {
  94.     short            i,x,y,ii,p = 0,dist,bt;
  95.     long                wrk;
  96.     long                xx,yy;
  97.     unsigned long        dum;
  98.     char                key;
  99.     Boolean            emp;
  100.     Point                mp;
  101.  
  102.     N_Cel_Put(1800,0x80000000+110,4,356);                            //PANEL
  103.     
  104.     Key_Process();
  105.     routine_step++;
  106.     
  107.     if (routine_step<64)
  108.     {
  109.         N_Cel_Put(1799,0x80000000+256,212,(short)(routine_step*4-92));
  110.     }
  111.     if (routine_step>=64 && routine_step<192)
  112.     {
  113.         N_Cel_Put(1799,0x80000000+256,212,164);
  114.     }        
  115.     if (routine_step>=192 && routine_step <300)
  116.     {
  117.         N_Cel_Put(1799,0x80000000+256,212,(short)164+((routine_step-192)*5));
  118.     }
  119.  
  120.     if (routine_step < 700) ii = routine_step;
  121.         else    ii = 700;
  122.  
  123.     for (i = 0;i!=ii;i++)
  124.     {
  125.         S1_X[i] += S1_MX[i]+GetRandom(0,10)-5;
  126.         if (S1_X[i]<-640*16)S1_X[i]=640*16;
  127.         if (S1_X[i]>640*16)S1_X[i]=-640*16;
  128.         S1_Y[i] += S1_MY[i]+GetRandom(0,10)-5;
  129.         if (S1_Y[i]<-640*16)S1_Y[i]=640*16;
  130.         if (S1_Y[i]>640*16)S1_Y[i]=-640*16;
  131.  
  132.         x = S1_X[i];
  133.         y = S1_Y[i];
  134.  
  135.         wrk = S1_D[i];
  136.         wrk = wrk / 16;
  137.         wrk = 16-wrk;
  138.  
  139.         if (wrk>14) wrk = 15;
  140.  
  141.         N_Cel_3D_Put(i,0x80000000+30+wrk,x,y,320,240,r,S1_D[i]);        
  142.         dist = S1_D[i] + speed;
  143.         if (dist <  0)                                                
  144.         {
  145.             dist = 512+dist;
  146.             N_Cel_Get(i,&emp,&dum,&x,&y);
  147.             N_Sp_Put(0x80000000+46,x-4,y-4);                        
  148.             S1_X[i] = GetRandom(0,640*32)-640*16;                    
  149.             S1_Y[i] = GetRandom(0,480*32)-480*16;
  150.         }            
  151.  
  152.         if (dist > 255)                                                
  153.         {
  154.             dist = dist -256;            
  155.             S1_X[i] = GetRandom(0,640*32)-640*16;                    
  156.             S1_Y[i] = GetRandom(0,480*32)-480*16;
  157.         }            
  158.         S1_D[i] = dist;
  159.     }
  160.     r=r+rs;
  161.     N_Cel_Loop2(0,0);                                                
  162.  
  163.     bt=N_Button_Check(0);
  164.  
  165.     if (bt==0) q=true;
  166.     if (bt==1) N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                    
  167.     if (bt==2)    speed--;
  168.     if (bt==3)    speed++;
  169.     if (bt==4)    rs--;
  170.     if (bt==5)    rs++;
  171. }
  172.  
  173. void Key_Process(void)
  174. {
  175.     char        ky;
  176.     
  177.     ky = N_Key_Get();
  178.     if (kb == false)
  179.     {
  180.         if ((ky & 0x01) !=0)
  181.         {
  182.             speed++;
  183.             N_Button_Push(0,3);
  184.             kb = true;
  185.         }    
  186.         if ((ky & 0x02) !=0)
  187.         {
  188.             rs--;
  189.             N_Button_Push(0,4);
  190.             kb = true;
  191.         }
  192.         if ((ky & 0x04) !=0)
  193.         {
  194.             rs++;
  195.             N_Button_Push(0,5);
  196.             kb = true;
  197.         }
  198.         if ((ky & 0x08) !=0)
  199.         {
  200.             speed--;
  201.             N_Button_Push(0,2);
  202.             kb = true;
  203.         }
  204.  
  205.         if ((ky & 0x40) !=0)
  206.         {
  207.             N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                    
  208.             N_Button_Push(0,1);
  209.             kb = true;
  210.         }
  211.     }    
  212.  
  213.     if ((ky & 0x80) !=0)
  214.     {
  215.         N_Button_Push(0,0);
  216.          q = true;
  217.     }
  218.     if (ky==0) kb = 0;
  219. }
  220.  
  221.  
  222.